import cv2
import numpy as np

def lbp_feature(image, block_size):
    # 计算LBP的neighborhood
    neighborhood = cv2.convertScaleAbs(image, alpha=(1.0/block_size))
 
    # 计算LBP cv2.LBP
    lbp_code, _ = cv2.xfeatures2d.LBP(neighborhood, None, None, cv2.LBP_UNSIGNED)
 
    return lbp_code

# 读取图像
image = cv2.imread('../yolo-cow/datasets/cow-nose/0001.jpg', 0)  # 加载灰度图像

# 设置LBP块的大小
block_size = 8

# 提取LBP特征
lbp_features = lbp_feature(image, block_size)

# 显示LBP特征
cv2.imshow('LBP Features', lbp_features)
cv2.waitKey(0)
cv2.destroyAllWindows()